package com.interview.ujiuye3;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * Copyright (C), 2018-2020
 * FileName: Poker
 * Author:   kongfanyu
 * Date:     2020/10/14 09:52
 */
public class Poker implements Comparable<Poker>{
    private Integer value;
    private Integer color;

    public Poker(Integer value, Integer color) {
        this.value = value;
        this.color = color;
    }

    @Override
    public String toString() {
        return "Poker{" +
                "value=" + value +
                ", color=" + color +
                '}';
    }

    @Override
    public int compareTo(Poker o) {
        if (this.value.compareTo(o.value) == 0){
            return  - this.color.compareTo(o.color);
        }else{
            return this.value.compareTo(o.value);
        }
    }

    public static void main(String[] args) {

        Poker poker1 = new Poker(1,3);//红桃A
        Poker poker2 = new Poker(1,4);//黑桃A
        Poker poker3 = new Poker(1,1);//方块A
        Poker poker4 = new Poker(13,2);//梅花K
        Poker poker5 = new Poker(13,3);//红桃K
        List<Poker> list = Arrays.asList(poker1,poker2,poker3,poker4,poker5);
        //创建一个有序的set
        Set<Poker> set = new TreeSet<>();
        for (Poker poker : list){
            set.add(poker);
        }
        System.out.println(set);
    }
}
